<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Progressive Play Server
 * Auth integration with Fracs V2
 * /libraries/auth.php
 * By: Yukwunhang
 */
require_once $_SERVER['DOCUMENT_ROOT'].'/fracsys/authenticate.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/fracsys/database.php';
class Auth
{
	var $fracs;
	var $dbase;
	/**
	 * Constructor
	 * 
	 * Initialize authenticate and database objects from the Fracs ACL Class.
	 * @return 
	 */
	function __construct()
	{
		$this->dbase = new database();
		$this->fracs = new authenticate();
	}
	
	/**
	 * Call the Fracs login function.
	 * Params are stored in $_POST.
	 * @return 
	 */
	function login()
	{
		$result = $this->fracs->login();
		return $result;
	}
	
	/**
	 * Check if the user is logged in.
	 * 
	 * Use the auth_status function from Fracs ACL class.
	 * @return 
	 */
	function logged_in()
	{
		$result = $this->fracs->auth_status();
		return $result;
	}
	
	/**
	 * Logout with Fracs ACL class.
	 * @return 
	 */
	function logout()
	{
		$result = $this->fracs->logout();
		return $result;
	}
	
	/**
	 * Convert username to ID.
	 * @return user ID
	 * @param object $username
	 */
	function id()
	{
		$id = $this->dbase->convert2_fid($this->fracs->username());
		return $id;
	}
	
	/**
	 * Return stats summary of a user
	 * @return 
	 */
	function quick_stats()
	{
		// Load models
		$CI =& get_instance();
		$CI->load->model('player_model', 'player');
		
		$result = $CI->player->get_player_quick_stats($this->id());
		// Get
		return $result;
	}
	
	// Destructor
	function __destruct()
	{
		$this->dbase->close_db();
	}
}

/*
 * End of file
 */